<?php
namespace App\Adshopuser\Models;
use Common\BaseModel;
class BShopAppConfig extends BaseModel
{
    public $res;
    public $expire;
    public function initialize()
    {
        parent::initialize();
        $this->setSource('b_shop_app_config');
    }

    public function find_list($type,$shop_id){
        $condition="type='{$type}' AND shop_id={$shop_id}";
        $list = $this::find(array(
            $condition
        ))->toarray();
        $new_news=[];
        foreach($list as $key=>$value){
            $new_news[$value['key']]=$value['value'];
        }
        return $new_news;
    }



    public function find_first_type($type){
        $user_info = $this->findFirstByType($type);
        return $user_info;
    }

    /**
     *  根据key值获取对应的等级
     */
    public function find_level_key($user_id){
        $user = new User();
        $user_info = $user->find_by_id($user_id);
        if($user_info){
            $level_config = 'level'.$user_info->level_id;
            $appconfigkey = $this->findFirstByKey($level_config);
            if(isset($appconfigkey->value)){
                return ['my_commisson'=>$appconfigkey->value,'max_commisson'=>0.8];
            }else{
                return ['my_commisson'=>'0.4','max_commisson'=>0.8];
            }
        }else{
            return ['my_commisson'=>'0.4','max_commisson'=>0.8];
        }
    }



    //获取用户等级的金额
    public function get_user_money($level){
        $keyvalue = $this->find_list('commission');
        $key = 'level'.$level;
        $data['self_money'] = $keyvalue[$key];
        $data['next_money'] = $keyvalue['level7'];
        $data['self_money_plus'] = 0;
        return $data;
    }


}